import { isEmpty, isUndefined } from 'lodash-es';
import { reactive } from 'vue';
import { ElMessage } from 'element-plus'
export default function opener() {
  const open = reactive({ data: {}, show: false, status: "" });
  return {
    open,
    showOpener(data = {}, status) {
      if (['edit', 'preview'].includes(status) && (isEmpty(data) || isUndefined(data))) {
        ElMessage.error({
          type: 'error',
          message: '请选择需要操作的数据'
        })
        return;
      }
      open.data = data;
      open.status = status;
      open.show = true;
    },
    closeOpener() {
      open.data = {};
      open.status = '';
      open.show = false;
    }
  }
}